package com.superhero.website.controller;

import cn.hutool.poi.excel.ExcelWriter;
import com.superhero.common.pojo.ApiResult;
import com.superhero.common.pojo.PageInput;
import com.superhero.common.pojo.vo.PageVo;
import com.superhero.common.pojo.vo.website.AccessStatisticVo;
import com.superhero.common.pojo.vo.website.TemperatureStatisticVo;
import com.superhero.common.utils.ExcelUtils;
import com.superhero.website.service.impl.StatisticServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Api(tags = {"后台管理系统"})
@RestController
@RequestMapping("/website/inspector")
public class StatisticController {

    @Autowired
    StatisticServiceImpl statisticService;

    @ApiOperation(value = "获取进入人员出入信息统计")
    @GetMapping("/accessStatistic")
    public ApiResult<AccessStatisticVo> getAccessStatistic() {
        AccessStatisticVo vo = statisticService.getAccessStatistic();
        return ApiResult.success(vo);
    }

    @ApiOperation(value = "获取进入人员体温信息统计")
    @GetMapping("/temperatureStatistic")
    public ApiResult<TemperatureStatisticVo> getTemperatureStatistic() {
        TemperatureStatisticVo vo = statisticService.getTemperatureStatistic();
        return ApiResult.success(vo);
    }

    @ApiOperation(value = "列表显示住户的出入记录", notes = "key可为人员姓名、检查人员姓名、出入类型（出/入），检查人员手机号，社区名称的全模糊查询")
    @GetMapping("/accessList")
    private ApiResult<PageVo> accessList(PageInput queryInput, String keyword) {
        return ApiResult.success(statisticService.accessList(queryInput, keyword));
    }

    @ApiOperation(value = "导出住户的出入记录")
    @GetMapping("/exportAccessList")
    private void exportAccessList(String keyword, HttpServletResponse response) {
        ExcelWriter excelWriter = statisticService.exportAccessList(keyword, response);
        if (null != excelWriter) {
            // 进行 excel 写出操作。
            try {
                ExcelUtils.responseExcel("住户出入记录", response, excelWriter);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
